package com.warm.androidstudy.utils;

import android.os.CountDownTimer;

/**
 * Created by LRJ on 2019/8/2.
 * Describe :倒计时通用工具类
 */
public class CommonCountDownTimer extends CountDownTimer {

    private OnCountDownTimerListener countDownTimerListener;

    public void setCountDownTimerListener(OnCountDownTimerListener listener) {
        this.countDownTimerListener = listener;
    }

    /**
     * @param millisInFuture    The number of millis in the future from the call
     *                          <p>
     *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
     *                          <p>
     *                          is called.
     * @param countDownInterval The interval along the way to receive
     *                          <p>
     *                          {@link #onTick(long)} callbacks.
     */


    public CommonCountDownTimer(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if (null != countDownTimerListener) {
            countDownTimerListener.onTick(millisUntilFinished);
        }
    }

    @Override
    public void onFinish() {
        if (null != countDownTimerListener) {
            countDownTimerListener.onFinish();
        }
    }

    public interface OnCountDownTimerListener {

        /**
         * 更新倒计时时间
         *
         * @param millisUntilFinished
         */
        void onTick(long millisUntilFinished);


        /**
         * 完成倒计时
         */
        void onFinish();
    }
   /* private void initCountDownTimer() {
        用法
        mCountDownTimer = new CommonCountDownTimer(30000, 1000);

        mCountDownTimer.setCountDownTimerListener(
                new CommonCountDownTimer.OnCountDownTimerListener() {
                    @Override
                    public void onTick(long millisUntilFinished) {

                        mEdit_content.setText("倒计时:" + millisUntilFinished / 1000);
                    }


                    @Override
                    public void onFinish() {
                        mEdit_content.setText("倒计时: 00");
                    }
                });
        mCountDownTimer.start();
    }*/
}
